
import React, { Component } from 'react';
import './indexnew.less';

// eslint-disable-next-line import/no-unresolved
import { createPage, base ,ajax,toast} from 'nc-lightapp-front';

const { NCModal, NCButton } = base;

const meta = {
    demo: {
        'items': [
            {
                attrcode: 'pk_org',
                itemtype: 'refer',
                label: '组织',
                isnextrow: true,
                required: true,
                visible: true,
                refname:'财务组织',
                refcode:"uapbd/refer/org/FinanceOrgTreeRef/index"
            },
            {
                attrcode: 'transdate',
                itemtype: 'datepicker',
                label: '交易日期',
                isnextrow: true,
                required: true,
                visible: true
            }
            
        ],
        'moduletype': 'form',
        'code': 'card_head',
        'name': '表头信息',
        'areaVisible': true,
        'isunfold': true,
        'status': 'add'
    }
};
const initTemplate = function(props) {
	props.meta.setMeta(meta);
};
class FormDemo11 extends Component {
    constructor(props) {
        super(props);
        this.state = {
            open: false
        };

        // props.use.form('demo');
        initTemplate.call(this, props);
    }

    onCloseClick = (props) => {
        let { self, pk, pre } = this.props;
        self.props.modal.close("modal");
    }
    onButtonClick = (props)=>{
        let pk_org = this.props.form.getFormItemsValue('demo','pk_org');
        let transdate = this.props.form.getFormItemsValue('demo','transdate');
        if(pk_org.value==""){
            toast({ color: "danger", content: "组织不能为空！" })
        }else if(transdate.value==null){
            toast({ color: "danger", content: "交易日期不能为空！" }) 
        }else{
             ajax({
            url: '/nccloud/obm/SummarysacVO/SummarysacVOGenMsg.do',
            data: {
                pk_org:pk_org,
                transdate:transdate
            },
            success: (data) => {
                  
                if(data.data.status=='success'){
                    toast({ color: 'success', content:data.data.msg });
                }else{
                    toast({ color: 'danger', content:data.data.msg });
                }
            },
        }); 
        }
      
    }
	render() {
		const { createForm } = this.props.form;
		return (
            <div>
            
                <NCButton
                    className="nc-bill-buttom-area-cancel"
                    colors="default"
                    id = "cancel"
                    onClick={this.onCloseClick.bind(this)}
                >
                    取消
                </NCButton> 
                <NCButton
                    className="nc-bill-buttom-area"
                    colors="primary"
                    id = "confirm"
                    onClick={this.onButtonClick.bind(this)}
                >
                    确定
                </NCButton> 
                {createForm('demo')}
            </div>
            );
	}

}
export default createPage({
	// initTemplate
})(FormDemo11);